﻿using CommonBase;
using MyAppProjectControl.BaseViewModels;
using Prism.Commands;
using Prism.Ioc;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MyAppProjectControl.ViewModels
{
    public class MainWindowViewModel : ViewBindModelBase
    {

        #region cmd
        private DelegateCommand _CloseCommand;
        public DelegateCommand CloseCommand =>
            _CloseCommand ?? (_CloseCommand = new DelegateCommand(CloseCommandMethod));

        private DelegateCommand _MaxCommand;
        public DelegateCommand MaxCommand =>
            _MaxCommand ?? (_MaxCommand = new DelegateCommand(MaxCommandMethod));

        private DelegateCommand _MinCommand;
        public DelegateCommand MinCommand =>
            _MinCommand ?? (_MinCommand = new DelegateCommand(MinCommandMethod));

        #endregion

        public MainWindowViewModel(IContainerExtension container) : base(container)
        {

        }

        public override  void ExecuteLoadedCommand()
        {
            base.ExecuteLoadedCommand();
      
            ToTargetConfigPage(SystemResource.Nav_IndexPageView);
        }



        public override void ExecuteUnLoadedCommand()
        {
            base.ExecuteUnLoadedCommand();
        }

        private void ToTargetConfigPage(string _PagName)
        {
            NavigationParameters itemParameter = new NavigationParameters();
            Application.Current?.Dispatcher.Invoke(() => {
                Region.RequestNavigate(SystemResource.Nav_MainContent, _PagName, itemParameter);
            });
        }

        private void MinCommandMethod()
        {
            Application.Current.MainWindow.WindowState = WindowState.Minimized;

        }

        private void MaxCommandMethod()
        {
            Application.Current.MainWindow.WindowState = Application.Current.MainWindow.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
        }

        private void CloseCommandMethod()
        {
            CommonStaticModel.IsQuiteApp = true;

            Application.Current.Shutdown();
            Console.WriteLine("退出软件");
        }
    }
}
